/* @(#)GSManufactureDownAction.java    V0.1
 *
 * Project: GSdevelop
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   owen         2006-2-22
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;

import com.hitrust.gs.form.GSManufactureDownForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

/**
 * 
 */
public class GSManufactureDownAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        GSManufactureDownForm tForm = (GSManufactureDownForm)aForm;
        String tOutputPath = tForm.getOutputpath();
        String tTemp=aForm.getRequest().getParameter("type");
        aForm.getResponse().setContentType( "application/doc;charset=UTF-16");
        aForm.getResponse().setHeader("Content-disposition","attachment; filename=" + tTemp+"_Error.xls" );

        File tFile = new File(tOutputPath);
        FileInputStream tInputStream = new FileInputStream(tFile);
        OutputStream tOutputStream = aForm.getResponse().getOutputStream();
        byte[] buff = new byte[1024];
        int readCount = 0;
        readCount = tInputStream.read(buff);
        while (readCount != -1){
            tOutputStream.write(buff, 0, readCount); 
           readCount = tInputStream.read(buff);
        }

        if (tInputStream!=null){
            tInputStream.close();
        }
        if (tOutputStream!=null){
            tOutputStream.close();
        }
        aForm.getRequest().setAttribute("success",tForm.getSucc());
        aForm.getRequest().setAttribute("fail",tForm.getFail());
        aForm.getRequest().setAttribute("faildown",tOutputPath);
        return GSBaseConstants.FORWARD_SUCCESS;
  
    }

}
